using System;
using System.Windows.Forms;
using System.Collections.Generic;

namespace SimpleDayView
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            _dayView.StartDate = DateTime.Now;
            _dayView.SelectionChanged += dayView1_SelectionChanged;

            _dayView.ShowSubHeader = true;

            var list = new List<string>();

            list.Add("Dentist 1");
            list.Add("Dentist 2");
            list.Add("Dentist 3");

            _dayView.SetSubHeaders(list);

            _showSubHeaders.Checked = false;

            _dayView.MouseMove += dayView1_MouseMove;

            if (_daysToShowComboBox.Items.Count > 0)
                _daysToShowComboBox.SelectedIndex = 0;
        }

        private void dayView1_MouseMove(object sender, MouseEventArgs e)
        {
            var gridCell = _dayView.GetCell(e.X, e.Y);

            if (gridCell == null)
                label2.Text = string.Empty;
            else
                label2.Text = string.Format("{0} : {1}", gridCell.Time, gridCell.CellIndex);
        }

        private void dayView1_SelectionChanged(object sender, EventArgs e)
        {
            label3.Text = string.Format("{0}:{1}", _dayView.SelectionStart, _dayView.SelectionEnd);
        }

        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            _dayView.CellHeight = trackBar1.Value;
        }

        private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
        {
            _dayView.StartDate = monthCalendar1.SelectionStart;
        }

        private void _daysToShowComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            var val = _daysToShowComboBox.SelectedItem as string;

            if (string.IsNullOrEmpty(val))
                return;

            int index;

            if (int.TryParse(val, out index))
                _dayView.DaysToShow = index;
        }

        private void _showSubHeaders_CheckedChanged(object sender, EventArgs e)
        {
            var checkBox = (CheckBox)sender;

            _dayView.ShowSubHeader = checkBox.Checked;
        }

        private void _hourFormat_CheckedChanged(object sender, EventArgs e)
        {
            var checkBox = (CheckBox)sender;

            _dayView.HourFormat = checkBox.Checked ? DayViewControl.HourFormatEnum.H_12 : DayViewControl.HourFormatEnum.H_24;
        }
    }
}